package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	//tm2, _ := time.Parse("2006-01-02", "2017-08-21")
	//
	//fmt.Println(tm2.Unix())
	//a := time.Now().Unix()
	//fmt.Println(a)
	//
	//fmt.Println(len(strconv.FormatInt(a, 10)))
	//match, _ := regexp.MatchString(".*?<\\?|\\?>|>|\\(", "<?peddach")
	//
	//fmt.Println(match)
	num := 123478.0
	str := FloatFormat(8, num)
	fmt.Println(str)
}

func FloatFormat(bit int, num float64) (str string) {

	str = strconv.FormatFloat(num, 'f', bit, 64)
	if len(str) < 4 {
		return str
	}
	arr := strings.Split(str, ".")
	length := len(arr[0])

	if length < 4 {
		return str
	}

	count := (length - 1) / 3

	for i := 0; i < count; i++ {
		arr[0] = arr[0][:length-(i+1)*3] + "," + arr[0][length-(i+1)*3:]
	}
	return strings.Join(arr, ".")
}
